<template>
    <div class="ceshi">
        <el-drawer :close-on-click-modal="false" class="hm-drawer" size="70%" direction="rtl" v-model="show"
            :before-close="handleClose">
            <template #header>
                <div class="hm-box-title">价格审核</div>
            </template>

            <div class="hm-form-item-box1">
                <div class="hm-form-title" style=" position: relative; ">商品信息</div>

                <el-row class="hm-row3 mb96" :gutter="60">
                    <div style="margin-left: 30px">
                        <image-preview :src="commoditydetailsData.productImage" :width="380" :height="260" />
                    </div>
                    <el-col :span="13">
                        <el-descriptions :column="2">
                            <el-descriptions-item width="50%" label="商品名称：">{{ commoditydetailsData.styleName
                                }}</el-descriptions-item>
                            <el-descriptions-item label="类目：">{{ commoditydetailsData.productCategoryName
                                }}</el-descriptions-item>
                            <el-descriptions-item label="商品编码：">{{ commoditydetailsData.productsId
                                }}</el-descriptions-item>

                            <el-descriptions-item label="品牌：">{{ commoditydetailsData.brandName
                                }}</el-descriptions-item>
                            <el-descriptions-item label="贸易方式：">{{ handleFilters(commoditydetailsData.tradeMode,
                                hm_trade_type)
                                }}</el-descriptions-item>
                            <el-descriptions-item label="售卖价格：">{{ commoditydetailsData.price }}</el-descriptions-item>
                            <el-descriptions-item label="是否走仓：">{{ commoditydetailsData.warehouse ? '是' : '否'
                                }}</el-descriptions-item>
                            <el-descriptions-item label="对接群名：">{{ commoditydetailsData.groupName
                                }}</el-descriptions-item>
                        </el-descriptions>
                    </el-col>
                </el-row>

                <div class="hm-form-title">直播补充信息</div>
                <div class="hm-form-mechanism">
                    <div class="mechanism_flex">
                        <div class="mechanism_div">
                            <div class="title">发货时间：</div>{{
                                commoditydetailsData.deliveryTime
                            }}
                        </div>
                        <div class="mechanism_div">
                            <div class="title">发货地：</div>{{
                                commoditydetailsData.placeDelivery
                            }}
                        </div>
                        <div class="mechanism_div">
                            <div class="title">物流/快递：</div>{{
                                commoditydetailsData.logistics
                            }}
                        </div>
                        <div class="mechanism_div">
                            <div class="title">适用人群：</div>{{
                                commoditydetailsData.eligibility
                            }}
                        </div>
                        <div class="mechanism_div">
                            <div class="title">厂家可用库存：</div>{{
                                commoditydetailsData.factoryStockNum
                            }}
                        </div>
                        <div class="mechanism_div">
                            <div class="title">不发货地区：</div>
                            <div class="value">{{
                                commoditydetailsData.noSendArea
                            }}</div>
                        </div>
                    </div>
                </div>
                <el-row>
                    <el-col :span="12" class="flex_div">
                        <div class="label">
                            <img src="@/assets/images/pdf.png" alt="">【{{ commoditydetailsData.styleName }}】信息卡 (A4) PDF
                        </div>
                        <div class="value">
                            <span @click="preview(commoditydetailsData.productsId)">预览</span>
                            <span @click="handleExport(commoditydetailsData.productsId)">下载</span>
                        </div>
                    </el-col>
                </el-row>

                <div class="hm-form-title">本次合作信息</div>
                <el-row class="content_div_cooperationMode">
                    <el-col :span="24">
                        <el-descriptions :column="3">
                            <el-descriptions-item label="商家名称：">{{ commoditydetailsData.supplierName
                                }}</el-descriptions-item>
                            <el-descriptions-item label="招商部：">{{ commoditydetailsData.recruiterDept
                                }}</el-descriptions-item>
                            <el-descriptions-item label="招商员：">{{ commoditydetailsData.recruiter
                                }}</el-descriptions-item>
                            <el-descriptions-item label="卖点：">{{ commoditydetailsData.sellingPoints
                                }}</el-descriptions-item>
                            <el-descriptions-item label="规格/材质：">{{ commoditydetailsData.specs
                                }}</el-descriptions-item>
                            <el-descriptions-item label="意向主播：">{{ commoditydetailsData.coreName
                                }}</el-descriptions-item>
                        </el-descriptions>
                        <div class="hm-form-mechanism" v-for="(item, index) in commoditydetailsData.hmMechanismsList"
                            :key="index">
                            <div class="mechanism_title">机制{{ index + 1 }}：</div>
                            <el-descriptions :column="3">
                                <el-descriptions-item label="合作方式：">{{ item.cooperationMode
                                    }}</el-descriptions-item>
                                <el-descriptions-item label="售价：">{{ item.price
                                    }}</el-descriptions-item>
                                <el-descriptions-item label="佣金：">{{ item.commission ? item.commission + '%'
                                    :
                                    ''
                                    }}</el-descriptions-item>
                                <el-descriptions-item label="直播机制：">{{ item.liveStreamingMechanism
                                    }}</el-descriptions-item>
                                <el-descriptions-item label="成本价：">{{ item.costPrice
                                    }}</el-descriptions-item>
                                <el-descriptions-item label="补充佣金：">{{ item.brokerage ? item.brokerage + '%' : '-'
                                    }}</el-descriptions-item>
                            </el-descriptions>
                        </div>
                    </el-col>
                </el-row>
                <div class="hm-form-title">核价信息</div>
                <div class="findings_audit_content">
                    <div class="column" v-for="(item, index) in logList" :key="index">
                        <div class="circle" :style="{ 'background-color': index == 0 ? '#109AFF' : '' }"></div>
                        <div v-if="index !== logList.length - 1" class="line"></div>
                        <div class="column_top">
                            <div class="adopt_proposal" :style="{ 'color': index == 0 ? '#109AFF' : '' }">{{ item.name
                                }}
                            </div>
                            <div class="adopt_proposals" :style="{ 'color': index == 0 ? '#109AFF' : '' }">{{ item.des
                                }}
                            </div>
                            <div class="danger_date">
                                {{ item.time }}
                            </div>
                        </div>
                        <div class="danger_name" v-if="item.title">
                            {{ item.title }}
                        </div>
                        <div class="content" v-if="!item.title">
                            <div class="content_flex" v-for="(ite, ind) in item.hmMechanismsList"
                                :key="ite.mechanismId">
                                <div v-if="ite.cooperationMode" class="content_flex_is">
                                    <div class="content_div">机制{{ ind + 1 + ':' }}</div>
                                    <div class="content_div">
                                        {{ ite.cooperationMode }}
                                    </div>
                                    <div class="content_div">
                                        {{ ite.cooperationMode == '分佣' ? ite.price : ite.costPrice }}
                                    </div>
                                    <div class="content_div">
                                        {{ ite.liveStreamingMechanism }}
                                    </div>
                                    <div v-if="ite.commission">
                                        {{ ite.commission + '%' }}
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
        </el-drawer>
    </div>
</template>
<script setup name="Commoditydetails" lang="ts">
// 暂用nickname代替商家名称

const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const { hm_trade_type } = toRefs<any>(proxy?.useDict('hm_trade_type'));
const { hm_cooperation_mode } = toRefs<any>(proxy?.useDict('hm_cooperation_mode'));
import { exportCertId } from '@/api/group/investmentPromotion/index'

const props = defineProps({
    commoditydetailsData: {
        type: Object,
        default: ''
    },
    dialogInfoVisible: {
        type: Boolean,
        default: false
    },
});
const logList = computed(() => {
    props.commoditydetailsData.logList.forEach((item: any) => {
        item.title = auditStatusNameById(item.auditStatus, item.auditRemark)
        item.name = handleName(item.auditStatus, item.auditor, item.creater)
        item.time = item.createTime
        item.des = handledes(item.auditStatus)
    })
    return props.commoditydetailsData.logList.reverse()
})
/** 处理不同状态回显的文字 */
const handledes = (auditStatus: string) => {
    if (auditStatus == '2') {
        return '已通过'
    } else if (auditStatus == '1') {
        return '重新议价'
    } else {
        return '发起核价'
    }
}
/** 处理不同状态回显的文字 */
const auditStatusNameById = (auditStatus: string, auditRemark: string) => {
    if (auditStatus == '0') {
        return ''
    } else if (auditStatus == '2') {
        return ''
    } else if (auditStatus == '1') {
        return auditRemark
    }
}
/** 处理不同状态回显的名字 */
const handleName = (auditStatus: string, auditor: string, createBy: string) => {
    if (auditStatus == '2') {
        return '核价人：' + auditor
    } else if (auditStatus == '1') {
        return '核价人：' + auditor
    } else {
        return '招商员：' + createBy
    }
}

const show = computed(() => props.dialogInfoVisible);
const emits = defineEmits(['doClose'])
const handleClose = () => {
    emits('doClose')
}
/** 预览 */
const preview = async (id: string) => {
    const resp: any = await exportCertId(id)
    const blob = window.URL.createObjectURL(new Blob([resp], { type: 'application/pdf' }));
    window.open(blob)
}
/** 下载 */
const handleExport = async (id: string) => {
    const resp: any = await exportCertId(id)

    // 创建一个Blob对象，并传入响应数据  
    const blob = new Blob([resp], { type: 'application/pdf' });

    // 创建一个指向该Blob对象的URL  
    const url = window.URL.createObjectURL(blob);

    // 创建一个下载链接，并模拟点击它  
    const link = document.createElement('a');
    link.href = url;
    link.setAttribute('download', `${props.commoditydetailsData.styleName}信息卡`); // 设置下载的文件名  
    document.body.appendChild(link);
    link.click();

    // 从DOM中移除链接，并释放URL对象  
    link.remove();
    window.URL.revokeObjectURL(url);
}
onMounted(() => {
})
</script>
<style lang="scss" scoped>
.hm-form-title {
    font-size: 16px;
    font-weight: bold;
    color: #1a1b1c;
    margin-bottom: 10px;
}

.flex_div {
    display: flex;
    margin-bottom: 10px;
    
    .label {
        min-width: 120px;
        font-size: 14px;
        background-color: rgba(240, 246, 255);
        padding: 4px 7px;

        img {
            width: 14px;
            height: 14px;
        }

        margin-right: 10px;
    }

    .value {
        color: #0094FF;
        font-weight: 400;
        font-size: 14px;
        line-height: 27px;
        cursor: pointer;

        span {
            margin-right: 30px;
        }
    }
}

.hm-drawer .el-drawer__header {
    margin-bottom: 0px !important;
}

.mb96 {
    margin-bottom: 10px;
}

.hm-box-title {
    font-weight: 600;
    font-size: 21px;
    color: #1C1D1E;
}

.content_div_cooperationMode {
    :deep(.el-descriptions) {
        height: auto !important;
    }

    :deep(.el-descriptions__cell) {
        width: 30% !important;
    }

    .hm-form-mechanism {
        position: relative;

        .mechanism_title {
            font-weight: 500;
            font-size: 14px;
            color: #1A1B1C;
            margin-bottom: 15px;
        }

        .delete_mechanism {
            width: 20px;
            height: 20px;
            position: absolute;
            right: 10px;
            top: 50%;
            cursor: pointer;
            z-index: 50;
        }
    }
}

.mechanism_flex {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    width: 100%;

    .mechanism_div {
        margin-bottom: 15px;
        width: calc(100% / 3);
        display: flex;
        align-items: center;
        color: #606266;
        font-size: 14px;

        .title {
            font-size: 14px;
            color: #303133;
            width: 100px;
        }

        .value {
            width: calc(100% - 100px);
            word-break: break-all;
        }
    }
}

.findings_audit_content {
    // height: 80px;
    width: 80%;
    display: flex;
    margin-top: 10px;
    justify-content: space-between;
    flex-wrap: wrap;

    .column {
        width: 100%;
        // display: flex;
        justify-content: space-between;
        align-items: flex-start;
        position: relative;

        .content {
            font-size: 14px;
            color: #AFB6C3;
            position: absolute;
            top: 0px;
            left: 430px;
            margin-left: 10px;

            .content_flex {
                .content_flex_is {
                    display: flex;
                    align-items: center;
                }

                .content_div {
                    margin-right: 10px;
                    line-height: 1;
                }
            }
        }

        .column_top {
            display: flex;
            height: 18px;
            margin-left: 10px;
            position: absolute;
            top: 0;
            left: 10px;
            align-items: center;
        }

        .circle {
            width: 11px;
            height: 11px;
            border-radius: 50%;
            margin-bottom: 70px;
            margin-top: 3px;
            border: 1px solid #109AFF;
        }

        .line {
            height: calc(100% - 11px);
            position: absolute;
            border-left: 1px solid #0094FF;
            top: 13px;
            left: 5px;
        }

        .adopt_proposal {
            font-size: 14px;
            line-height: 1.4;
        }

        .adopt_proposals {
            font-size: 14px;
            line-height: 1.4;
            margin-left: 10px;
        }

        .danger_name {
            font-size: 14px;
            color: #AFB6C3;
            position: absolute;
            top: 0px;
            left: 430px;
            margin-left: 10px;
        }

        .danger_date {
            font-size: 14px;
            color: #B8BECA;
            margin-left: 10px;
        }

    }

}

:deep(.el-descriptions) {
    height: 100%;
}

:deep(.el-descriptions__body) {
    height: 100%;
}

:deep(.el-descriptions__table) {
    height: 100%;
}
</style>